package com.daotingli.backendprograms.Service.Admin.Reader;

import com.daotingli.backendprograms.Repository.Admin.Reader.ReaderRepository;
import com.daotingli.backendprograms.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ReaderService {
    @Autowired
    private ReaderRepository readerRepository;
    public Result getAllReaders() {

        return Result.success(readerRepository.getAllReaders());
    }

    public Result addReader(String username, String password, String identity, String userphone, String userstate) {
        Map<String, Object> map = readerRepository.addReader(username, password, identity, userphone, userstate);
        if("success".equals(map.get("status"))){
            return Result.success();
        }else {
            return Result.error((String) map.get("message"));
        }

    }

    public Result deleteReader(Integer id) {
        Map<String, Object> map = readerRepository.deleteReader(id);
        if("success".equals(map.get("status"))){
            return Result.success();
        }else{
            return Result.error((String) map.get("message"));
        }
    }

    public Result updateReader(Integer id, String username, String password, String identity, String userphone, String userstate) {
        Map<String, Object> map = readerRepository.updateReader(id, username, password, identity, userphone, userstate);
        if("success".equals(map.get("status"))){
            return Result.success();
        }else{
            return Result.error((String) map.get("message"));
        }
    }
}
